﻿#ifndef _CMAP_H_
#define _CMAP_H_
#include "xList.h"

#ifdef __cplusplus
extern "C" {
#endif

#define INT_KEY_CMP_FUNC    0
#define GET_VALUE_FROM_IT(it) (((XMAP_PEER*)((char*)it.ptr + sizeof(void*) * 2))->value)
typedef int(*CMAP_KEY_COMPARE_FUNC)(void* k1, void* k2);

typedef struct _map_peer_ {
	void* key;
	void* value;
} XMAP_PEER;

typedef struct _cmap_itorator {
	//attribute
	void* ptr;

	//action
	void* (*next)(struct _cmap_itorator* thes);
} CMapIterator;

typedef struct _cmap_ {
	//value
	XList list;
	CMAP_KEY_COMPARE_FUNC cmp_fn;

	//action
	int (*insert)(struct _cmap_* thes, void* key, void* value);
	void* (*find)(struct _cmap_* thes, void* key);
	void* (*begin)(struct _cmap_* thes);
	void* (*end)(struct _cmap_* thes);
	int (*release)(struct _cmap_* thes);
} XMap;

int construct_map(XMap* thes, CMAP_KEY_COMPARE_FUNC comp_fn);
int construct_cmap_iterator(CMapIterator* thes);

#ifdef __cplusplus
}
#endif
#endif
